package tazadum.engine.trigger;

public class SwitchTrigger implements Trigger {
	private final boolean initialValue;
	private final float threshold;
	private float state = 0;

	public SwitchTrigger(final boolean initialValue, final float threshold) {
		this.initialValue = initialValue;
		this.threshold = threshold;
	}

	@Override
	public boolean trigger(final float value) {
		if (value > state) {
			state = value;
		}
		if (state > threshold) {
			return !initialValue;
		}
		return initialValue;
	}

}
